﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SubsidyApp.Models;

namespace SubsidyApp.Models
{
    public class ContentRepository
    {
        public IQueryable<site_zone> GetAllZones()
        {
            return BasesDescription.db.site_zones.AsQueryable();
        }

        public IQueryable<site_distribution> GetAllDistributions()
        {
            return BasesDescription.db.site_distributions;
        }

        public IQueryable<site_content> GetAllPages()
        {
            return BasesDescription.db.site_contents.OrderBy(c => c.content_created).AsQueryable();
        }

        public IQueryable<site_zone> GetMenu()
        {
            return from site_zone in BasesDescription.db.site_zones
                   where site_zone.zone_visible == true
                   select site_zone;
        }

        public IQueryable<site_distribution> GetZoneDistributions(int id)
        {
            return from site_distrib in BasesDescription.db.site_distributions
                   where site_distrib.zone_id == id
                   select site_distrib;
        }

        public IQueryable<site_content> GetPages(int zone_id, int id)
        {
            return from site_content in BasesDescription.db.site_contents
                   where site_content.site_distribution.zone_id == zone_id && site_content.distrib_id == id 
                   && site_content.content_approved == true
                   orderby site_content.content_created
                   select site_content;
        }

        public site_zone GetZone(int id)
        {
            return BasesDescription.db.site_zones.SingleOrDefault(x => x.id == id);
        }

        public site_distribution GetDistribution(int id)
        {
            return BasesDescription.db.site_distributions.SingleOrDefault(x => x.id == id);
        }

        public site_content GetPage(int id)
        {
            return BasesDescription.db.site_contents.Single(p => p.id == id);
        }
    }
}